package cn.zaichi.edu.excelcommon.utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public final class DateFormatUtil {

    /**
     * 日期格式yyyy-MM-dd
     */
    public static String DATE_PATTERN = "yyyy-MM-dd";

    /**
     * 日期时间格式yyyy-MM-dd HH:mm:ss
     */
    public static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    /**
     * 日期时间格式 HH:mm:ss
     */
    public static String TIME_PATTERN = "HH:mm:ss";



    /**
     * 构造函数
     */
    private DateFormatUtil() {
        super();
    }


    /**
     * 字符串
     * @param date
     * @param dateFormat
     * @return
     */
    public static String LocalDateToString(String date,String dateFormat){
        LocalDateTime localDateTime = LocalDateTime.parse(date, DateTimeFormatter.ofPattern(DATE_TIME_PATTERN));
        return localDateTime.format(DateTimeFormatter.ofPattern(dateFormat));
    }

    /**
     * Date转LocalDateTime
     *
     * @param date Date对象
     * @return
     */
    public static LocalDateTime StringToLocalDateTime(String date) {



        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN);

        return LocalDateTime.parse(date, formatter);
    }

    /**
     * 字符串转 LocalDate
     *
     * @param date
     * @return
     */
    public static LocalDate StringToLocalDate(String date) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN);
        return LocalDate.parse(date, formatter);
    }

    /**
     * 字符串转 LocalTime
     *
     * @param time
     * @return
     */
    public static LocalTime StringToLocalTime(String time,String dateFormat) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
        return LocalTime.parse(time, formatter);
    }


}